<?php
session_start();
if(empty($_SESSION['user'])){
    echo "请先登录";
    $url='/index.php';
    echo "<a href='".$url."'>".'返回首页'."</a>";
    die();
}
?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<a href="index.php">返回首页</a><br>

<?php
include "functions.php";
$bookid=$_POST['bookid'];
$bookname=$_POST['bookname'];

if(!effectBook2($bookid)){
    echo "书编号不存在或者已在库中";
    echo "<br>";
    $url1='/return.php';
    echo "<a href='".$url1."'>".'重新进行还书操作'."</a><br>";
    $url2='/index.php';
    echo "<a href='".$url2."'>".'返回首页'."</a>";
    die();
}

//把还书时间写入Record表
$dbh=connectDB();
$statement = $dbh->prepare('update Record set ReturnTime=:time where Book=:ID');
$statement->execute([':time'=>date('Y-m-d'),':ID'=>$bookid]);

//把数据库中书表和借阅记录表的该书状态改为在库：1
$flag='1';
updateBookStatus($bookid,$flag);
updateRecordStatus($bookid,$flag);
echo "还书成功！\n";
$url='/index.php';
echo "<a href='".$url."'>".'返回首页'."</a>";
?>



</body>
</html>